home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / unix / include / sys / fcntl.h < prev    next >
C/C++ Source or Header  |  2008-08-09  |  7KB  |  194 lines

  1. /*-
  2.  * Copyright (c) 1983, 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)fcntl.h    5.14 (Berkeley) 7/1/91
  34.  */
  35.  
  36. #ifndef _FCNTL_H_
  37. #define    _FCNTL_H_
  38.  
  39. /*
  40.  * This file includes the definitions for open and fcntl
  41.  * described by POSIX for <fcntl.h>; it also includes
  42.  * related kernel definitions.
  43.  */
  44.  
  45. #ifndef KERNEL
  46. #include <sys/types.h>
  47. #endif
  48.  
  49. /*
  50.  * File status flags: these are used by open(2), fcntl(2).
  51.  * They are also used (indirectly) in the kernel file structure f_flags,
  52.  * which is a superset of the open/fcntl flags.  Open flags and f_flags
  53.  * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
  54.  * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
  55.  */
  56. /* open-only flags */
  57. #define    O_RDONLY    0x0000        /* open for reading only */
  58. #define    O_WRONLY    0x0001        /* open for writing only */
  59. #define    O_RDWR        0x0002        /* open for reading and writing */
  60. #define    O_ACCMODE    0x0003        /* mask for above modes */
  61.  
  62. #ifdef KERNEL
  63. /*
  64.  * Kernel encoding of open mode; separate read and write bits
  65.  * that are independently testable: 1 greater than the above.
  66.  */
  67. #define    FREAD        0x0001
  68. #define    FWRITE        0x0002
  69. #endif
  70. #define    O_NONBLOCK    0x0004        /* no delay */
  71. #define    O_APPEND    0x0008        /* set append mode */
  72. #ifndef _POSIX_SOURCE
  73. #define    O_SHLOCK    0x0010        /* open with shared file lock */
  74. #define    O_EXLOCK    0x0020        /* open with exclusive file lock */
  75. #define    O_ASYNC        0x0040        /* signal pgrp when data ready */
  76. #define    O_FSYNC        0x0080        /* synchronous writes */
  77. #endif
  78. #define    O_CREAT        0x0100        /* create if nonexistant */
  79. #define    O_TRUNC        0x0200        /* truncate to zero length */
  80. #define    O_EXCL        0x0400        /* error if already exists */
  81. #ifdef KERNEL
  82. #define    FMARK        0x1000        /* mark during gc() */
  83. #define    FDEFER        0x2000        /* defer for next gc pass */
  84. #define    FHASLOCK    0x4000        /* descriptor holds advisory lock */
  85. #endif
  86.  
  87. /* defined by POSIX 1003.1; BSD default, so no bit required */
  88. #define    O_NOCTTY    0        /* don't assign controlling terminal */
  89.  
  90. #ifdef KERNEL
  91. /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
  92. #define    FFLAGS(oflags)    ((oflags) + 1)
  93. #define    OFLAGS(fflags)    ((fflags) - 1)
  94.  
  95. /* bits to save after open */
  96. #define    FMASK        (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  97. /* bits settable by fcntl(F_SETFL, ...) */
  98. #define    FCNTLFLAGS    (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
  99. #endif
  100.  
  101. /*
  102.  * The O_* flags used to have only F* names, which were used in the kernel
  103.  * and by fcntl.  We retain the F* names for the kernel f_flags field
  104.  * and for backward compatibility for fcntl.
  105.  */
  106. #ifndef _POSIX_SOURCE
  107. #define    FAPPEND        O_APPEND    /* kernel/compat */
  108. #define    FASYNC        O_ASYNC        /* kernel/compat */
  109. #define    FFSYNC        O_FSYNC        /* kernel */
  110. #define    FNONBLOCK    O_NONBLOCK    /* kernel */
  111. #define    FNDELAY        O_NONBLOCK    /* compat */
  112. #define    O_NDELAY    O_NONBLOCK    /* compat */
  113. #endif
  114.  
  115. /*
  116.  * Constants used for fcntl(2)
  117.  */
  118.  
  119. /* command values */
  120. #define    F_DUPFD        0        /* duplicate file descriptor */
  121. #define    F_GETFD        1        /* get file descriptor flags */
  122. #define    F_SETFD        2        /* set file descriptor flags */
  123. #define    F_GETFL        3        /* get file status flags */
  124. #define    F_SETFL        4        /* set file status flags */
  125. #ifndef _POSIX_SOURCE
  126. #define    F_GETOWN    5        /* get SIGIO/SIGURG proc/pgrp */
  127. #define F_SETOWN    6        /* set SIGIO/SIGURG proc/pgrp */
  128. #endif
  129. #define    F_GETLK        7        /* get record locking information */
  130. #define    F_SETLK        8        /* set record locking information */
  131. #define    F_SETLKW    9        /* F_SETLK; wait if blocked */
  132.  
  133. /* file descriptor flags (F_GETFD, F_SETFD) */
  134. #define    FD_CLOEXEC    1        /* close-on-exec flag */
  135.  
  136. /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
  137. #define    F_RDLCK        1        /* shared or read lock */
  138. #define    F_UNLCK        2        /* unlock */
  139. #define    F_WRLCK        3        /* exclusive or write lock */
  140. #ifdef KERNEL
  141. #define    F_WAIT        0x010        /* Wait until lock is granted */
  142. #define    F_FLOCK        0x020         /* Use flock(2) semantics for lock */
  143. #define    F_POSIX        0x040         /* Use POSIX semantics for lock */
  144. #endif
  145.  
  146. /*
  147.  * Advisory file segment locking data type -
  148.  * information passed to system by user
  149.  */
  150. struct flock {
  151.     short    l_type;        /* lock type: read/write, etc. */
  152.     short    l_whence;    /* type of l_start */
  153.     off_t    l_start;    /* starting offset */
  154.     off_t    l_len;        /* len = 0 means until end of file */
  155.     pid_t    l_pid;        /* lock owner */
  156. };
  157.  
  158.  
  159. #ifndef _POSIX_SOURCE
  160. /* lock operations for flock(2) */
  161. #define    LOCK_SH        0x01        /* shared file lock */
  162. #define    LOCK_EX        0x02        /* exclusive file lock */
  163. #define    LOCK_NB        0x04        /* don't block when locking */
  164. #define    LOCK_UN        0x08        /* unlock file */
  165. #endif
  166.  
  167.  
  168. #ifndef KERNEL
  169. #include <sys/cdefs.h>
  170.  
  171. __BEGIN_DECLS
  172. int    open __P((const char *, int, ...));
  173. int    creat __P((const char *, mode_t));
  174. int    fcntl __P((int, int, ...));
  175. #ifndef _POSIX_SOURCE
  176. int    flock __P((int, int));
  177. #endif /* !_POSIX_SOURCE */
  178. __END_DECLS
  179. #endif
  180.  
  181. #ifdef AMIGA
  182. #define O_NO_CLOSE 0x100    /* An available value, means don't close
  183.                    underlying resource */
  184. /* Note: S_ISVTX (sticky) is mapped to the pure bit.
  185.          The amiga script bit is mapped to world execute ...
  186.      user S_IWRITE is the and of the amiga write & delete bits.
  187.      group S_IWRITE is the amiga write bit.
  188.      world S_IWRITE is the amiga delete bit.
  189.      We always set the archive bit off.
  190. */
  191. #endif
  192.  
  193. #endif /* !_FCNTL_H_ */
  194.